/*
 * Copyright (c) 2017 - 2019, AEye, Inc.
 * All rights reserved.
 */

#ifdef _MSC_VER
#include <Windows.h>
#include <processthreadsapi.h>
#else
#include <pthread.h>
#endif

#include "Utils.hpp"

namespace aeye {

std::string trim(const std::string &instr, const std::string &patt) {
  const auto strBegin = instr.find_first_not_of(patt);
  if (strBegin == std::string::npos)
    return "";
  const auto strEnd = instr.find_last_not_of(patt);
  const auto strRange = strEnd - strBegin + 1;
  return instr.substr(strBegin, strRange);
}

#ifdef _MSC_VER
void set_thread_name(const wchar_t *name) {
  SetThreadDescription(GetCurrentThread(), name);
}
#elif __APPLE__
void set_thread_name(const char *name) {
  pthread_setname_np(name);
}
#else
void set_thread_name(const char *name) {
  pthread_setname_np(pthread_self(), name);
}
#endif

}

